Sudoku Solver

Solve Sudoku puzzles of size 9 X 9.


This program is based on an article that explains two programmatic ways to solve the puzzle written in Java. The simpler and slower method is implemented here. A Sudoku puzzle is a square matrix of numbers with four constraints on the number in each square. The matrix is of length and width SIZE. Further the matrix is divided into smaller boxes with SIZE total squares. Thus the four constraints are:

The Sudoku grid is modeled as a two-dimensional array of numbers from 0 to SIZE, where 0 implies that the cell has not yet been filled. Methods are defined to check the uniqueness of a square by looking at the lines/box it resides in for a similar number. If the number is already present then true is returned. To find the box containing the square of interest a simple method using the modulo function is used. Next a function is written that calls each of these constraint checks in turn. The final constraint that the square has a number is implemented in the solving algorithm.

The solving algorithm is known as a back tracking algorithm. One thing I am unsure of: does it require a number in every row and column initially or do all Sudoku puzzles have this requirement for solution.



Input Sudoku Puzzle









Hit the button:

Reload the browser window/tab between solutions to reinitialize the puzzle.